package com.zr.Inquiry.controller;


import com.zr.Inquiry.pojo.*;
import com.zr.Inquiry.service.InquiryService;
import com.zr.utils.ErrorMessage;
import com.zr.utils.ResultBuilderVo;
import com.zr.utils.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * @ClassName InquiryController
 * @Description TODO
 * @Author xiaowei
 * @Date 2019/12/27 15:03
 * @Version 1.0
 */
@RestController
@CrossOrigin
public class InquiryController {
    @Autowired
    private InquiryService inquiryService;
    //partner/queryByLegalPerson?legalPersonId 供应商下拉框
    @GetMapping("partner/queryByLegalPerson")
    public ResultVo queryByLegalPerson(Integer legalPersonId){
    if (legalPersonId==null){
            return ResultBuilderVo.error(ErrorMessage.IDISNOT);
        }
       ResultVo resultVo= inquiryService.queryByLegalPerson(legalPersonId);

    return  resultVo;
    }
    // inquiryList/search 分页查询
    @PostMapping("inquiryList/search")
    public ResultVo queryPage(@RequestBody InquirySelectVo inquirySelectVo){
        return inquiryService.queryPage(inquirySelectVo);
    }
    //查询 inquirySheet/see
    @PostMapping("inquirySheet/see")
    public ResultVo see(@RequestBody InquiryTotalVo inquiryTotalVo){
        return  inquiryService.see(inquiryTotalVo.getRequestForQuotationId());
    }

    //inquiryList/add 新增
    @PostMapping("inquiryList/add")
  public ResultVo add(@RequestBody @Valid InquiryAddandUpdateVo inquiryAddandUpdateVo, BindingResult bindingResult){
        ResultVo resultVo= inquiryService.add(inquiryAddandUpdateVo);
        if(bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
         return resultVo;
    }
 //inquiryList/update 修改
    @PostMapping("inquiryList/update")
  public ResultVo update(@RequestBody @Valid InquiryAddandUpdateVo inquiryAddandUpdateVo, BindingResult bindingResult){
        ResultVo resultVo= inquiryService.update(inquiryAddandUpdateVo);
        if(bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return resultVo;
    }

    //选择备件
    @PostMapping("inquiryList/selectMaterial")
    public ResultVo selectMaterial(@RequestBody SelectSpareVo selectSpareVo){
        return inquiryService.selectMaterial(selectSpareVo);

    }
    //选择供应商
    @PostMapping("material/searchPartnerPage")
    public ResultVo searchPartnerPage(@RequestBody SelectPartnerVo selectPartnerVo){
        return inquiryService.searchPartnerPage(selectPartnerVo);
    }
    //inquiryList/modifyState 作废
    @PostMapping("inquiryList/modifyState")
    public ResultVo modifyState(@RequestBody InquiryTotalVo inquiryTotalVo){
        return inquiryService.modifyState(inquiryTotalVo);
    }
    //审核
    @PostMapping("inquiryAuditor/update")
    public ResultVo inquiryAuditorUpdate(@RequestBody InquiryTotalVo inquiryTotalVo){
        return inquiryService.inquiryAuditorUpdate(inquiryTotalVo.getRequestForQuotationId());
    }

    //导入

    @PostMapping("quotation/InquiryIntroduction")
    public ResultVo InquiryIntroduction(MultipartFile file)throws Exception{
        return inquiryService.inquiryIntroduction(file);
    }


}
